<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 一次性计时器
        // window.setTimeout(函数,毫秒值)
        // window.clearTimeout(timer)

        // 周期性计时器
        // window.setInterval(函数,毫秒值)
        // window.clearInterval(timer)

        var timer;
        var timer2;
        function go(){
            console.log("welcome to 南京");
        }
        function show(){
            timer=window.setTimeout(go,3000);//隔2s执行go函数，go不需要加小括号，回调函数
            console.log(timer);
        }

        function show2(){
            timer2=setTimeout(function(){
                console.log("哈哈，我爱南京");
            },2000);//隔2s执行匿名函数
            console.log(timer2);
        }
        function doClear(){
            window.clearTimeout(timer);//取消计时器，清除计时器
        }

        function run(){
            console.log("我们去度蜜月");
        }
        var timer3;
        var timer4;
        function show3(){
           timer3= window.setInterval(run,1000);//每隔1s调用run函数
           console.log(timer3);
        }
        function show4(){
           timer4= window.setInterval(function(){
                console.log("哈哈哈");
           },1000);//每隔1s调用run函数
           
        }
        function doClear2(){
            window.clearInterval(timer3);
        }
    </script>
</head>
<body>
    <input type="button" value="一次性计时器" onclick="show()">
    <input type="button" value="一次性计时器" onclick="show2()">
    <input type="button" value="清除一次性计时器" onclick="doClear()">
    <input type="button" value="周期性计时器" onclick="show3()">
    <input type="button" value="周期性计时器" onclick="show4()">
    <input type="button" value="清除周期性计时器" onclick="doClear2()">
</body>
</html>